#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int i;
    
    char *str1 = (char *)malloc(3*sizeof(char));
    char *str2 = (char *)calloc(10, sizeof(char));

    printf("malloc:");
    for (i = 0; i < 10; i++) {
        printf("%c",str1[i]);
    }

    printf("\ncalloc:");
    for (i = 0; i < 10; i++) {
        printf("%c",str2[i]);
    }
    printf("\n");

    strncpy(str1, "12341111111123123123123", sizeof(str1));
    printf("之前的大小:%ld\n", strlen(str1));
    str1 = (char *)realloc(str1, 2 * sizeof(char));
    strncpy(str1, "12341111111123123123123", 3*sizeof(char));
    printf("之后的大小:%ld\n", strlen(str1));
    
    free(str1);
    free(str2);

    return 0;
}

